package com.yykj.user.center.server.controller.patient;


import com.yykj.common.vo.ResultVO;
import com.yykj.user.center.server.form.DisablePatient;
import com.yykj.user.center.server.form.RelaceAvatarForm;
import com.yykj.user.center.server.service.patient.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "患者信息相关接口")
@RestController
@RequestMapping("/api/patient")
@SuppressWarnings("unchecked")
@Slf4j
public class PatientController {
    @Autowired
    private LoginService loginService;


    @PostMapping("/replaceAvatar")
    @ApiOperation("替换头像")
    public ResultVO replaceAvatar(@Valid @RequestBody RelaceAvatarForm relaceAvatarForm) {
        return ResultVO.success(loginService.replaceAvatar(relaceAvatarForm));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "姓名", required = false, dataType = "String"),
            @ApiImplicitParam(name = "mobile", value = "手机号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "hospitalId", value = "医院Id", required = false, dataType = "Integer"),
    })
    @GetMapping("/getByHospitalId")
    @ApiOperation("用户管理信息")
    public ResultVO getByHospitalId(@RequestParam(value = "current", required = false, defaultValue = "0") Integer current,
                                    @RequestParam(value = "size", required = false, defaultValue = "100") Integer size,
                                    @RequestParam(value = "name", required = false) String name,
                                    @RequestParam(value = "mobile", required = false) String mobile,
                                    @RequestParam(value = "hospitalId", required = true) Integer hospitalId) {
        return ResultVO.success(loginService.getByHospitalId(current,size,name,mobile,hospitalId));
    }

    @PostMapping("/disable")
    @ApiOperation("禁用账户")
    public ResultVO disable(@Valid @RequestBody DisablePatient disablePatient) {
        return ResultVO.success(loginService.disable(disablePatient));
    }

    @GetMapping("/getRelation")
    @ApiOperation("获取关联的所有就诊卡信息")
    public ResultVO getRelation(@RequestParam(value = "id", required = true) String id) {
        return ResultVO.success(loginService.getRelation(id));
    }
}
